HAL CRC initialization and configuration functions migration ¶
The goal of this page is to show how to migrate the initialization sequence using STM32CubeMX2:
Open STM32CubeMX2 CRC configuration panel.
Configure the SW layer HAL.
Configure the CRC main features.
Generate the code
HAL CRC configuration panel ¶
Create a new project with the STM32CubeMX2, then start the initialization and the main configuration.
HAL CRC main features configuration ¶
Configure the CRC main features.
Generated CRC initialization and de-initialization sequences ¶
The CRC initialization and de-initialization sequences are generated in the
mx_crc_hal_init
function in the
mx_crc.c
file under
$YOUR_PROJECT_NAME$/$YOUR_PROJECT_NAME$_SW/generated/STM32Cube_CodeGen.
Related concepts:
|
Topic |
HAL1 Code Snippet |
HAL2 Code Snippet |
|---|---|---|
|
Handle declaration |
CRC_HandleTypeDef hcrc;
|
hal_crc_handle_t hCRC;
|
|
Initialization and configuration sequence |
static void MX_CRC_Init(void)
{
hcrc.Instance = CRC;
hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;
hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;
hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_WORDS;
if (HAL_CRC_Init(&hcrc) != HAL_OK)
{
Error_Handler();
}
}
void HAL_CRC_MspInit(CRC_HandleTypeDef* hcrc)
{
if(hcrc->Instance==CRC)
{
/* Peripheral clock enable */
__HAL_RCC_CRC_CLK_ENABLE();
}
}
|
hal_crc_handle_t *mx_crc_hal_init(void)
{
HAL_RCC_CRC_EnableClock();
if (HAL_CRC_Init(&hCRC, HAL_CRC) != HAL_OK)
{
return NULL;
}
return &hCRC;
}
|
|
Deinitialization sequence |
static void MX_CRC_DeInit(void)
{
HAL_CRC_DeInit(&hCRC);
}
void HAL_CRC_MspDeInit(CRC_HandleTypeDef* hcrc)
{
if(hcrc->Instance==CRC)
{
/* Peripheral clock disable */
__HAL_RCC_CRC_CLK_DISABLE();
}
}
|
void mx_crc_hal_deinit(void)
{
(void)HAL_CRC_DeInit(&hCRC);
HAL_RCC_CRC_Reset();
HAL_RCC_CRC_DisableClock();
}
|